
/**
 * 引入自定义文件
 */
const formidable = require('./formidable');
const response = require('./response');
const error = require('./error');
const koaBody = require('koa-bodyparser');// 获取post参数第三方插件
const database = require('./database');
const cors = require('koa2-cors');
const config = require('../config/index');
const xss = require('./xss');

/**
 * 参数解析
 * https://github.com/koajs/bodyparser
 */
const mdFormidable = formidable();

/**
 * 处理post参数
 */
const mdKoaBody = koaBody({
  enableTypes: [ 'json', 'form', 'text', 'xml' ],
  formLimit: '56kb',
  jsonLimit: '1mb',
  textLimit: '1mb',
  xmlLimit: '1mb',
  strict: true
});

/**
 * 统一返回格式
 */
const mdResHandler = response();
/**
 * 错误处理
 */
const mdErrorHandler = error();

/**
 * 数据库连接
 */
// const mdDatabaseHandler = database();

/**
 * 跨域
 */
const mdCors = cors(config.cors);


/**
 * xss攻击处理
 */
const mdXss = xss();

module.exports = [
  mdXss,
  // mdFormidable,
  mdKoaBody,
  mdResHandler,
  mdErrorHandler,
  // mdDatabaseHandler,
  mdCors
];
